package algorithm.leetcode.array;

import java.util.ArrayList;
import java.util.List;

/**
 * 最大子数组的和
 */
public class MaxSubArrAdd {

     public int maxSubArray(int[] nums) {
         if(nums.length == 0) {
              return 0;
          }

          if(nums.length == 1) {
              return nums[0];
          }

         int max = nums[0];
         int curMax = nums[0];
         for(int i = 1; i<nums.length; i++) {
             curMax = Math.max(nums[i], curMax + nums[i]);
             max = Math.max(max, curMax);
         }
         return max;
     }

    public int[] productExceptSelf(int[] nums) {
        int sum = 1;
        for(int i=0; i<nums.length; i++) {
            sum = sum * nums[i];
        }

        for(int i=0; i<nums.length; i++) {
            if(nums[i] != 0) {
                nums[i] = sum / nums[i];
            } else {
                nums[i] = 0;
            }
        }

        return nums;
    }

    public static void main(String[] args) {


    }
}
